package com.caht.controller.user;

import com.caht.DTO.PostsDTO;
import com.caht.VO.PostsandUserVO;
import com.caht.entity.Posts;
import com.caht.result.Result;
import com.caht.servier.PostsServier;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 文章接口
 */
@RestController
@RequestMapping("/user/posts")
@Slf4j
public class PostsController {
    /**
     * 管理文章 Servier
     */
    @Autowired
    private PostsServier postsServier;

    /**
     * 上传文章信息
     * @param postsDTO
     * @return
     */
    @PostMapping("/addposts")
    public Result addposts(@RequestBody PostsDTO postsDTO){
        log.info("文章信息:{}",postsDTO);
        Posts posts = new Posts();
        BeanUtils.copyProperties(postsDTO,posts);
        postsServier.addposts(posts);
        return Result.success();
    }

    /**
     * 查询文章列表
     * @param
     * @return
     */
    @GetMapping
    public Result<List<PostsandUserVO>> postsResult(){
        List<PostsandUserVO> posts = postsServier.postsResult();
        return Result.success(posts);
    }



}
